Sample to demonstrate using the Picture Utilities Package
The guts of this is in the window creation function: DoCreateWindow( PicHandle thePicture ) DoCreateWindow is passed a picture handle and if the global gUsePictPalette is set it will use the pict utils package (PUP) to get the color table stored in the pict. You could this source to sample direct color images, but to keep things as clear as possible this application only deals with 8 bit images.
We use the PUP to get the color table for the image. This is passed into NewGWorld and it is also used to create a palette that is attached to the window.
Note that we use PUP to sample the image that was stored in the file. We interrogate a PicHandle read directly from the file. There are also routines for sampling PixMaps, but dont forget that if you are in an indexed color environment, and you sample a PixMap, if you didnt set up the color environment when your first created the PixMap, the colors may not be as you expect.
To see an example of this there are two 8-bit images included with this snippet. One is a spectral ramp, the other a green/brow ramp. Both have approx 120 or so colors.
to see an example of what PUP may report if you didnt set the colors for a window up properly before displaying open one of the files with the "use picture palette" item from the palette menu toggled off.
In this case it will use the "wrong" set of colors to try to draw the image (it just uses what ever the default system color table is). If you get PUP to sample (by toggling on the "use picture palette" item from the palette menu the picture is rendered correctly.
Building the Code
This project was built and tested on CodeWarrior 2.1 using CarbonLib 1.1a3. Since this is a Carbon app, the "Carbon Support" folder of the CarbonSDK should be in the same folder as the CodeWarrior IDE. If this is not the case, the CarbonLib library will have to be re-added to the project. In addition, the CarbonLib extension needs to be in the extension folder. The CarbonSDK (which contains the library and the extension) can be found on Apple's website: http://developer.apple.com/sdk/
Restrictions
Nearly every sample requires more memory than the 384KB CodeWarrior sets as the default heap size. If for some reason the memory has been reset to the default (either through converting the project or whatever) the memory should be reset to 1000 - 2000KB (depending on the application). This can be achieved by going to the projects settings (Edit Menu->C-PPC Settings... under CodeWarrior 2.1) and selecting the "PPC Target" under the "Target" tab.
Other Code Notes
This sample used to be a "non-Carbon" sample, but has been carbonized for demonstration purposes. The "old" code has been left in (commented out) in order to compare and contrast the Carbon versus non-Carbon APIs.